<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip" v-if="false">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from "./login-form";
import { mapActions } from "vuex";
export default {
  components: {
    LoginForm,
  },
  methods: {
    ...mapActions(["userLogin", "getResource"]),
    async handleSubmit({ name, userName, password, showRegis }) {
      try {
        if (showRegis) {
          let res = await regisUser({
            name,
            userName,
            password: password,
            type: "user",
          });
          console.log(res);
          this.$Message.success("注册成功！");
        } else {
          await this.userLogin({
            name,
            password,
          });
          await this.getResource();
          this.$router.push({
            name: "Portal",
            query:{
              id:'123'
            }
          });
        }
      } catch (err) {
        console.log(err.message);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background-image: url("../../assets/images/login-bg.jpg");
  background-size: cover;
  background-position: center;
  position: relative;
  &-con {
    position: absolute;
    right: 160px;
    top: 50%;
    transform: translateY(-60%);
    width: 300px;
    &-header {
      font-size: 16px;
      font-weight: 300;
      text-align: center;
      padding: 30px 0;
    }
    .form-con {
      padding: 10px 0 0;
    }
    .login-tip {
      font-size: 10px;
      text-align: center;
      color: #c3c3c3;
    }
  }
}
</style>
